package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JsonUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 游记
 */
@Setter
@Getter
public class Travel extends BaseDomain{
    /**
     *草稿 0
     *待审核 1
     *拒绝 -1
     *已发布 2
     */
    public static final Integer STATE_REJECT = -1;
    public static final Integer STATE_DRAFT= 0;
    public static final Integer STATE_WAIT = 1;
    public static final Integer STATE_RELEASE = 2;

    //标题
    private String title;
    //旅游时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date travelTime;
    //人均消费
    private String perExpends;
    //旅游天数
    private Integer days;
    //和谁旅游
    private Integer person;
    //作者
    private User author;
    //创建时间
    private Date createTime;
    //发布时间
    private Date releaseTime;
    //是否公开
    private Boolean isPublic;
    //旅游地区
    private Region place;
    //封面
    private String coverUrl;
    //最后更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;
    //状态
    private Integer state;
    //游记内容
    private TravelContent travelContent;
    //点赞数
    private List<Click> nums;

    public String getStateName(){
        String stateName = "草稿";
        if (this.state == STATE_REJECT){
            stateName = "拒绝";
        }else if (this.state == STATE_WAIT){
            stateName = "待发布";
        }else if (this.state == STATE_RELEASE){
            stateName = "已发布";
        }
        return  stateName;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("state",state);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        //添加作者id
        if(author!=null){
            map.put("authorId",author.id);
        }
        return JsonUtil.toJsonString(map);
    }

}